package com.woniuxy.thred.others;

/**
 * description: ThredLocal <br>
 * date: 2022/2/6 7:02 下午 <br>
 * author: shesaifei <br>
 * version: 1.0 <br>
 */

/**
 * InheritableThreadLocal:继续上下文 环境 数据 拷贝一份给子线程
 * 1、构造器：哪里调用 就属于哪里 找线程体
 * 2、run方法：本线程自身
 */
public class ThreadLocalTest04 {

    private static ThreadLocal<Integer> threadLocal = new InheritableThreadLocal<>();

    public static void main(String[] args) {
        threadLocal.set(2);
        System.out.println(Thread.currentThread().getName() + "-->" + threadLocal.get());

        //线程由main线程开辟
        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "-->" + threadLocal.get());
            threadLocal.set(200);
            System.out.println(Thread.currentThread().getName() + "-->" + threadLocal.get());
        }).start();
    }

}
